﻿using System;
using System.Linq;
using Framework.Poco;
using Shell.DomainDot;
using System.Collections.Generic;

namespace Framework.Domain
{
    /// <summary>
    /// 文章分类选择器
    /// </summary>
    public class SelectCategory : DomainDotBase
    {
        /// <summary>
        /// 所有的文章分类
        /// </summary>
        public WithAll<Category> Categories { private get; set; }

        public IEnumerable<Category> GetAllCategories()
        {
            return this.Categories;
        }

        public Category FindCategory(string name)
        {
            var category = this.GetAllCategories().SingleOrDefault(c => c.Name.Equals(name));
            if (category != null)
            {
                return category;
            }
            return null;
        }

        public Category Select(Guid? identity)
        {
            return this.Categories.SingleOrDefault(c => c.Id.Equals(identity.Value));
        }

        /// <summary>
        /// 获取指定Id的文章分类
        /// </summary>
        public Category Select(Guid identity)
        {
            return this.Categories.SingleOrDefault(i => i.Id.Equals(identity));
        }
    }
}
